local oilDrum = love.graphics.newImage("resources/images/intro/OilDrum.png")
local fizz = love.graphics.newImage("resources/images/intro/Fizz.png")
local loveEngine = love.graphics.newImage("resources/images/intro/LoveEngine.png")
local image
local startTime
local timer

local function introImage(i)
  image = i
  startTime = love.timer.getTime()

  hook.Add("draw", "introImage", drawImage)
end


function drawImage()
  timer = (love.timer.getTime()-startTime)*80

  if timer<255 then
    love.graphics.setColor(255,255,255,timer)
    love.graphics.draw(image, ScrW()/2 - image:getWidth()/2, ScrH()/2 - image:getHeight()/2, 0, 1, 1)
  elseif timer>=255 and timer<2*255 then
    love.graphics.setColor(255,255,255,255-1-timer)
    love.graphics.draw(image, ScrW()/2 - image:getWidth()/2, ScrH()/2 - image:getHeight()/2, 0, 1, 1)
  elseif timer>2*255 then
    startTime = love.timer.getTime()
    hook.Remove("introImage")
    if image ~= fizz then hook.Call("introImageEnd", {}) else areas.titleScreen() end
  end

end

function switchImage()
  startTime = love.timer.getTime()
  timer = (love.timer.getTime()-startTime)*100

  if image==oilDrum then
    introImage(loveEngine)
  elseif image==loveEngine then
    introImage(fizz)
  elseif image==fizz then 
    hook.Remove("introImageEnd")
    return
  end
end

hook.Add("introImageEnd", "introImageEnd", switchImage)


introImage(oilDrum)